package com.www.applyword.ui.home;

import com.www.applyword.Constants.Constants;
import com.www.applyword.R;
import com.www.applyword.adapter.GirdDropDownAdpter4;
import com.www.applyword.base.BaseActivity;
import com.www.applyword.bean.GoodListBean;
import com.www.applyword.http.CallBack;
import com.www.applyword.http.HttpClient;
import com.www.applyword.utils.SPUtil;
import com.www.applyword.view.MyGridView;
import com.www.applyword.view.MyImageLoader;
import com.youth.banner.Banner;
import com.youth.banner.BannerConfig;
import com.youth.banner.Transformer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * author : huang
 * date   : 2019/11/19 0019 17:50
 * version: 1.0
 */
public class MyGoodListActivity extends BaseActivity {
    @BindView(R.id.bannerContainer)
    Banner mBanner;
    @BindView(R.id.gv)
    MyGridView gv;

    private List<String> list_path = new ArrayList<>();
    private List<GoodListBean.IntegerGoodsListBean> integerGoodsList = new ArrayList<>();
    private GirdDropDownAdpter4 cityAdapter;

    @Override
    protected void loadViewLayout() {
        setContentView(R.layout.good_list_activity);
        setTitle("积分商城");

    }

    @Override
    protected void loadData() {
        cityAdapter = new GirdDropDownAdpter4(this, integerGoodsList);
        gv.setAdapter(cityAdapter);

        list_path.clear();

        //设置样式，里面有很多种样式可以自己都看看效果
        mBanner.setBannerStyle(BannerConfig.CIRCLE_INDICATOR);
        //设置图片加载器
        mBanner.setImageLoader(new MyImageLoader());
        //设置轮播的动画效果,里面有很多种特效,可以都看看效果。
        mBanner.setBannerAnimation(Transformer.Default);
        //  mBanner.setBannerTitles(list_title);
        //设置轮播间隔时间
        mBanner.setDelayTime(3000);
        //设置是否为自动轮播，默认是true
        mBanner.isAutoPlay(true);
        //设置指示器的位置，小点点，居中显示
        mBanner.setIndicatorGravity(BannerConfig.CENTER);

        Map<String, Object> params = new HashMap<>();
        params.put("UserID", SPUtil.getString(Constants.USERID));
        params.put("Page", "1");
        params.put("Rows", "20");
        HttpClient.get(MyGoodListActivity.this, Constants.GETINTEGERGOODSLIST, params, new CallBack<GoodListBean>() {
            @Override
            public void onSuccess(GoodListBean goodListBean) {
                integerGoodsList.clear();
                integerGoodsList.addAll(goodListBean.getIntegerGoodsList());
                cityAdapter.notifyDataSetChanged();
                list_path.clear();
                for (GoodListBean.BannerBean bannerBean : goodListBean.getBanner()) {
                    list_path.add(bannerBean.getBanner_Url());
                }
                mBanner.setImages(list_path).start();
            }
        });
    }
}
